# -*- coding: utf-8 -*-

from base import BaseHandler

class XmlHandler(BaseHandler):
	""" Handles XHTML and XML files """
	def handle_start(self):
		if(not self.environ.has_key('renyare.config')):
			self._err("No config variable")
		if(self.environ.has_key('renyare.transform') and self.environ['renyare.transform'][0]): # local transformer
			path_part = self.environ['renyare.config']['local']['modules']['static'].rstrip('/')+'/'+self.module
		else:
			path_part = self.environ['renyare.config']['web']['modules'].rstrip('/')+'/'+self.module
		if(self.module_type == "html"):
			self.data_file = path_part+".html"
		else:
			self.data_file = path_part+".xml"
		if(self.module_type == "html"): self.addStylesheet('xhtml.xsl', 'xsl')
		doc = self.environ['renyare.application']['document']
		node = self.environ['renyare.application']['node']
		file_node = doc.createElementNS(None, 'file')
		file_node.appendChild(doc.createCDATASection(self.data_file))
		node.appendChild(file_node)

	def handle_end_unparsed(self):
		return '' #self.xml.toxml("UTF-8")
